﻿using System;
using System.Collections.Generic;

namespace ZoeEngine.Framework
{
    /// <summary>
    /// Comparer implementation to allow on-the-fly sorting of a collection of IDrawn objects
    /// based on their set draw order. This allows us to optimize the drawing procedure each frame.
    /// </summary>
    internal class DrawOrderComparer : IComparer<IDrawn>
    {
        public static readonly DrawOrderComparer Default = new DrawOrderComparer();
        public int Compare(IDrawn x, IDrawn y)
        {
            if ((x == null) && (y == null))
            {
                return 0;
            }

            if (x != null)
            {
                if (y == null)
                {
                    return -1;
                }
                if (x.Equals(y))
                {
                    return 0;
                }
                if (x.DrawOrder < y.DrawOrder)
                {
                    return -1;
                }
            }

            return 1;
        }
    }
}
